<template>
  <div class="smart-query-form">
    <a-tabs v-model:activeKey="activeKey" @change="changeTab">
      <a-tab-pane key="1" v-privilege="'workOrderBomDetail:query'" forceRender tab="BOM资料">
        <work-order-bom-detail-list ref="bomDetailRef" />
      </a-tab-pane>
    </a-tabs>
  </div>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import WorkOrderBomDetailList from './components/work-order-bom-detail-list.vue';

  const activeKey = ref('1'); // 直接设置默认值
  const orderInfoRef = ref();

  function setOrderInfo(orderInfo) {
    orderInfoRef.value = orderInfo;
    // 主动触发一次数据更新
    updateChildComponents();
  }

  const bomDetailRef = ref();

  function updateChildComponents() {
    if (!orderInfoRef.value) return;

    switch (activeKey.value) {
      case '1':
        bomDetailRef.value?.setOrderInfo?.(orderInfoRef.value);
        break;
    }
  }

  function changeTab(e) {
    activeKey.value = e;
    updateChildComponents();
  }

  defineExpose({
    setOrderInfo,
  });
</script>
